package com.smartleanx.module.hrm.dal.mysql.esign;



import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.mybatis.core.mapper.BaseMapperX;
import com.smartleanx.module.hrm.service.esign.temp.param.HrmEContractTempParam;
import com.smartleanx.module.hrm.service.esign.temp.po.HrmEContractTemp;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;

/**
 * e签报合同模板Mapper
 *
 * @author dongbidongxin
 * @since 2025-07-07 15:56:14
 */
@Mapper
public interface HrmEContractTempMapper extends BaseMapperX<HrmEContractTemp> {

    default PageResult<HrmEContractTemp> getDocTempPage(HrmEContractTempParam param, List<Long> tempIds){
        LambdaQueryWrapper<HrmEContractTemp> wrapperX = new LambdaQueryWrapper<>();
        wrapperX.eq(HrmEContractTemp::getDataStatus,1);
        wrapperX.like(StrUtil.isNotBlank(param.getTempName()),HrmEContractTemp::getTempName,param.getTempName());
        wrapperX.eq(StrUtil.isNotBlank(param.getTempCreateName()),HrmEContractTemp::getTempCreateName,param.getTempCreateName());
        wrapperX.eq(StrUtil.isNotBlank(param.getTempUpdateName()),HrmEContractTemp::getTempUpdateName,param.getTempUpdateName());
        if(ArrayUtil.isNotEmpty(param.getDeptNames())){
            wrapperX.in(HrmEContractTemp::getCorpId, Arrays.asList(param.getDeptNames()));
        }
        wrapperX.eq(param.getTempStatus()!=null,HrmEContractTemp::getTempStatus,param.getTempStatus());
        if(CollUtil.isNotEmpty(tempIds)){
            wrapperX.in(HrmEContractTemp::getId,tempIds);
        }
        if(param.getCreateTime()!=null && param.getCreateTime().length>0){
            wrapperX.between(HrmEContractTemp::getCreateTime,param.getCreateTime()[0],param.getCreateTime()[1]);
//            wrapperX.lt(HrmEContractTemp::getCreateTime,param.getCreateTime()[0]);
        }
        if(param.getUpdateTime()!=null && param.getUpdateTime().length>0){
            wrapperX.between(HrmEContractTemp::getUpdateTime,param.getUpdateTime()[0],param.getUpdateTime()[1]);
//            wrapperX.lt(HrmEContractTemp::getUpdateTime,param.getUpdateTime()[0]);
        }

        return selectPage(param, wrapperX);
    }

}
